import { MongoClient, ObjectId as objectId } from "mongodb"

const url = process.env.NUXT_DB_HOST  // 此时已包含数据库名

export async function connect() {
    const client = new MongoClient(url)  // 直接使用完整连接字符串
    await client.connect()
    console.log('Connected successfully to MongoDB server')
    const db = client.db()  // 无需传参，自动使用连接字符串中的数据库名
    return { client, db }
}

export function close(client) {
    client.close()
    console.log(' Disconnected successfully to MongoDBserver')
}

export const ObjectId = objectId


